package com.ht.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ht.modules.system.entity.ActVariableConfig;
import com.ht.modules.system.entity.ActVariableConfigVo;
import com.ht.modules.system.mapper.ActVariableConfigMapper;
import com.ht.modules.system.service.IActVariableConfigService;
import com.ht.utils.DicConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *  审批流程变量配置
 * @Author:
 * @Date:   2021-09-27
 * @Version: V1.0
 */
@Service
public class ActVariableConfigServiceImpl extends ServiceImpl<ActVariableConfigMapper, ActVariableConfig> implements IActVariableConfigService {

    @Autowired
    private ActVariableConfigMapper actVariableConfigMapper;

    @Override
    public Page<ActVariableConfigVo> list(Page<ActVariableConfigVo> page, ActVariableConfigVo actVariableConfigVo,
                                          String column, String order) {
        return page.setRecords(actVariableConfigMapper.list(page, actVariableConfigVo, column, order));
    }

    @Override
    public void add(ActVariableConfig actVariableConfig) {
        actVariableConfig.setDelFlag(DicConstants.DEL_FLAG_WSC);
        this.save(actVariableConfig);
    }

    @Override
    public void edit(ActVariableConfig actVariableConfig) {
        ActVariableConfig actVariableConfigEntity = this.getById(actVariableConfig.getId());
        if (actVariableConfigEntity == null){
            throw new RuntimeException("未找到对应实体！");
        }
        this.updateById(actVariableConfig);
    }

    @Override
    public void delete(String id) {
        ActVariableConfig actVariableConfig = this.getById(id);
        if (actVariableConfig == null){
            throw new RuntimeException("未找到对应实体！");
        }
        actVariableConfig.setDelFlag(DicConstants.DEL_FLAG_YSC);
        this.updateById(actVariableConfig);
    }

    @Override
    public void deleteBatch(String ids) {
        if (ids == null || "".equals(ids.trim())){
            throw new RuntimeException("参数不识别！");
        }
        actVariableConfigMapper.updateBatchByIds("del_flag", DicConstants.DEL_FLAG_YSC, ids.split(","));
    }

    @Override
    public ActVariableConfig queryById(String id) {
        ActVariableConfig actVariableConfig = this.getById(id);
        if (actVariableConfig == null){
            throw new RuntimeException("未找到对应实体！");
        }
        return actVariableConfig;
    }

}
